package cn.edu.scau.cmi.liyetian.singleton;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.liyetian.multiton.Marshal;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class MyController implements Initializable{
	String strTextarea1 = "";
	String strTextarea2 = "";

	@FXML
	private Label label1;
	
	@FXML
	private TextField text1;
	
	@FXML
	private Button button1;
	
	@FXML
	private TextArea textarea1;
	
	
	@FXML
	private Label label2;
	
	@FXML
	private TextField text2;
	
	@FXML
	private Button button2;
	
	@FXML
	private TextArea textarea2;
	
	
	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO Auto-generated method stub
		
	}
	
	public void showSingleton(ActionEvent event) {
		System.out.println("Button Click button 1");
		String name = text1.getText();
		if(Chairman.isExist()) {
			strTextarea1 = strTextarea1+"你要创建"+name+"但是已经创建了这个类的单例，不能创建新的对象了，你现在获取的对象是"+Chairman.getName()+"\r\n";
		}
		else {
			Chairman chairman = Chairman.getInstance(name);
			strTextarea1 = strTextarea1+chairman.getName()+chairman+"\r\n";
		}
		textarea1.setText(strTextarea1);
	}
	
	public void showMultiton(ActionEvent event) {
		System.out.println("Button Click button 2");
		String name2 = text2.getText();
		if(Marshal.isfull()) {
			strTextarea2 = strTextarea2+"你已经创建了10个元帅，不能再创建了"+"\r\n";
		}
		else {
			if(!Marshal.isExist(name2)) {
				Marshal marsahal = Marshal.add(name2);
				strTextarea2 = strTextarea2 + name2+marsahal+"\r\n";
			}
		}
		textarea2.setText(strTextarea2);
	}

}
